package cn.tedu.boyou.search.query;

import cn.tedu.boyou.common.query.QueryObject;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.util.StringUtils;

import java.util.Date;

@Setter@Getter
public class SaleQueryObject extends QueryObject{

    private Date[] state_schedule;
    private Integer[] priceArea;
    private Boolean[] promotion;
    private String[] tags;

    private String orderBy = "id";//排序
    private String sort = "asc";   //

    public void setOrderBy(String orderBy){
        if (StringUtils.hasLength(orderBy)){
            this.orderBy = orderBy;
        }
    }

    public Pageable getPageable(){
        PageRequest of;
        if (sort.equals("desc")){
            of = PageRequest.of(super.getCurrentPage() - 1, super.getPageSize(), Sort.Direction.DESC, orderBy);
        }else {
            of = PageRequest.of(super.getCurrentPage() - 1, super.getPageSize(), Sort.Direction.ASC, orderBy);
        }
        return of;
    }
    public Pageable getPageableWithoutSort(){
        PageRequest of = PageRequest.of(super.getCurrentPage() - 1, super.getPageSize());
        return of;
    }


}
